package com.longxi.tianjintianbao.ui.presenter.task;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.MyTaskListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.task.MyTaskListFragment;
import com.longxi.tianjintianbao.ui.view.task.IMyTaskListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class MyTaskListAtPresenter extends BasePresenter<IMyTaskListAtView> {

    private MyTaskListPagerAdapter myTaskListPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未接单");
        mCategoryList.add("已接单");
        mCategoryList.add("已完成");
        mCategoryList.add("无法完成");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public MyTaskListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTitle("我的任务");
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initVariable();
    }

    public void initViewPager(){
        myTaskListPagerAdapter = new MyTaskListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList());
        getView().getViewPager().setAdapter(myTaskListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        MyTaskListFragment myTaskListFragment = (MyTaskListFragment) myTaskListPagerAdapter.getCurrentFragment();
        myTaskListFragment.refreshReceiptList();
    }

    @Override
    public void detachView() {
        super.detachView();
        this.myTaskListPagerAdapter = null;
    }
}
